$(document).ready(function(){
    $("#changeLogin").click(function(){
        changeLogin(); 
    });
    
    $("#change").click(function(){
        changePassword(); 
    });
    
    $("#setIpRestrict").click(function() {
        setIpRestrict(); 
    });
    
    $("#deleteIpRestrict").click(function(){
        $("#passwordConfirmDeleteRestrict").show("fast");
        $("#iready").show("slow");
        $("#youCome").hide("fast");
        $("#IHidden").show("slow");
    });
    
    $("#iready").click(function(){
        deleteiprestriction();
    });
});

function changeLogin() {
    var newLogin = $("#newLogin").val();
    var password = $("#passwordChangeLogin").val();
    var answer = $("#answer").val();
    $("#newLogin").attr("disabled", true);
    $("#password").attr("disabled", true);
    $("#answer").attr("disabled", true);
    $("#imgLoad").show();
    $.ajax({
        type: "POST",
        url: "ajax.php",
        data: {
            'changeLogin' : 'changeLogin', 
            'newLogin' : newLogin,
            'password' : password,
            'answer' : answer
        },
        success: function(msg) {
            $("#changeLoginShow").html(msg);
            $("#imgLoad").hide();
        }
    })
}

function changePassword() {
    var oldPassword = $("#old_password").val();
    var new_password = $("#new_password").val();
    var new_password_confirm = $("#new_password_confirm").val();
    var mail = $("#mail").val();
    var answer = $("#answer").val();
    $("#old_password").attr("disabled", true);
    $("#new_password").attr("disabled", true);
    $("#new_password_confirm").attr("disabled", true);
    $("#mail").attr("disabled", true);
    $("#answer").attr("disabled", true);
    $("#imgLoad").show();
    $.ajax({
        type: "POST",
        url: "ajax.php",
        data: {
            'change' : 'change',
            'old_password' : oldPassword,
            'new_password' : new_password,
            'new_password_confirm' : new_password_confirm,
            'mail' : mail,
            'answer' : answer
        },
        success: function(msg) {
            $("#showChangePassword").html(msg);
            $("#imgLoad").hide();
        }
    })
}

function setIpRestrict() {
    var ip = $("#ip").val();
    $("#ip").attr("disabled", true);
    $("#imgLoad").show();
    $("#setIpRestrict").hide();
    $("#setIpRestrictInvisible").show();
    $.ajax({
        type: "POST",
        url: "ajax.php",
        data: {
            'setIpRestrict' : 'setIpRestrict',
            'ip' : ip
        },
        success: function(msg) {
            $("#ipRestrictShow").html(msg);
            $("#imgLoad").hide();
            $("#setIpRestrictInvisible").hide();
            $("#setIpRestrictDone").show();
        }
    });
}

function deleteiprestriction() {
    $("#imgLoad").show();
    var password = $("#passwordConfirmDeleteRestrict").val();
    $("#iready").attr("disabled", true);
    $("#passwordConfirmDeleteRestrict").attr("disabled", true);
    $.ajax({
        type: "POST",
        url: "ajax.php",
        data: {
            'deleteIpProtect' : 'deleteIpProtect',
            'password' : password
        },
        success: function(msg) {
            $("#ipRestrictShow2").html(msg);
            $("#setForce").show();
            $("#imgLoad").hide();
        }
    });
}

function openPasswordAndButton () {
    $("#passwordConfirmDeleteRestrict").attr("disabled", false);
    $("#iready").attr("disabled", false);
}
